import socket,threading

class TalkClient:
    def __init__(self):
        self.client = socket.socket()  # 实例化socket对象
    def connect_server(self):
        # 1. 建立与服务器端的连接
        # 2. 发送数据
        # 3. 关闭连接
        self.client.connect(('192.168.0.117',1111))
        threading.Thread(target=self.send).start()
        threading.Thread(target=self.receive).start()

    def send(self):
        while True:
            to_msg = input("")    # 发送消息
            self.client.send(to_msg.encode())
    def receive(self):
        while True:
            from_msg = self.client.recv(1024).decode()     # 接收消息
            print(from_msg)

    def __del__(self):
        self.client.close()

if __name__ == '__main__':
    tc = TalkClient()
    tc.connect_server()